<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="渠道" prop="tag">
        <el-select
          v-model="queryParams.tag"
          placeholder="请选择类型"
          clearable
          size="small"
          style="width: 200px"
        >
          <el-option
            v-for="item in tagOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 200px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          clearable
          size="small"
          style="width: 200px"
        >
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="suggestList">
      <el-table-column type="index" width="150" align="center"/>
      <el-table-column label="类型" prop="tag" width="150">
        <template slot-scope="scope">
          <div v-if="scope.row.tag == 3">投诉</div>
          <div v-else-if="scope.row.tag == 4">建议</div>
        </template>
      </el-table-column>
      <el-table-column label="内容" prop="content" align="center" :show-overflow-tooltip="true" width="300"/>
      <el-table-column label="投诉/建议人" prop="workerName" :show-overflow-tooltip="true" width="200"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" width="200"/>
      <el-table-column label="处理状态" align="center" width="150">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            :active-value="2"
            :inactive-value="1"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="200" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-link type="primary" @click="handOpenImage(scope.row.id)">链接</el-link>
        </template>
      </el-table-column>
    </el-table>


    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="60%"
    >

        <div class="block" v-for="item in imgSrc " :key="item">
          <el-image
            style="width: 50%; height: 30%"
            :src="item"
            fit="contain"></el-image>
        </div>
        <span slot="footer" class="dialog-footer">
              <el-button type="primary" @click="dialogVisible = false">关 闭</el-button>
        </span>

    </el-dialog>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {listSuggestList, changeStatus, getImg} from "@/api/job/suggest/suggestApi";

export default {
  name: "suggest",
  data() {
    return {
      imgSrc: [],
      dialogVisible: false,
      // 遮罩层
      loading: true,
      suggestList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      companyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      signUp: false,
      // 黑名单下拉
      statusOptions: [{value: 1, label: '未处理'}, {value: 2, label: '已处理'}],
      tagOptions: [{value: 3, label: '投诉'}, {value: 4, label: '建议'}],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        //渠道名称
        tag: undefined,
        //状态
        status: undefined
      },
      // 表单参数
      suggestApi: [],
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {

    /** 获取员工信息列表 */
    getList() {
      this.loading = true;
      listSuggestList(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
          this.suggestList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        tag: undefined,
        status: undefined,
        createTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    //黑名单
    handleStatusChange(row) {
      let text = row.status == "2" ? "已处理" : "未处理";
      this.$confirm('确认标记"' + text + '""' + row.id + '"吗?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return changeStatus(row.id, row.status);
      }).then(() => {
        this.msgSuccess(text + "成功");
      }).catch(function () {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    handOpenImage(id) {
      this.dialogVisible = true
      getImg(id).then(res => {
        this.imgSrc = res.data;
      })
    }
  }
};
</script>
